#!coding:utf8
'''
Created on Aug 17, 2012

@author: join
'''

from jnius import autoclass
import os
from ConfigParser import ConfigParser
import logging
from xml.dom.minidom import parseString

LOG = logging.getLogger('console')

def load_lottery_conf():
    if os.path.exists("/etc/lottery/lottery.conf"):
        filename = "/etc/lottery/lottery.conf"
    else:
        filename = os.path.join(os.path.dirname(os.path.dirname(__file__)),'lottery.conf')
    c = ConfigParser()
    try:
        c.read(filename)
        return dict(c.items('default'))
    except Exception as e:
        LOG.exception("系统发生异常，异常为：%s" % e)
        pass
#        print 'can not read config of service : thor.conf',e

conf_dict = load_lottery_conf()
agentcode=conf_dict.get("lottery.agentcode")
url=conf_dict.get("lottery.url")
key=conf_dict.get("lottery.key")

def queryBalance():
    '''查看公司额度账户余额接口'''
    QueryBalance = autoclass("com.rbc.http.bean.QueryBalance")
    bean = QueryBalance()
    bean.setAgentCode(agentcode)
    print bean.toXmlString()
    resXml = bean.call(url,key)
    return resXml

def parseXml2dom(res_xml):
    res_xml = res_xml.replace('encoding="gb2312"', 'encoding="utf-8"')
    dom = parseString(res_xml)
    return dom
    
#queryBalance()

if __name__ == '__main__':
#    queryBalance()
    pass
#    dom = parseString(s)
#    resp_node = dom.getElementsByTagName('Resp')[0]
#    print resp_node.getAttribute('errcode')
#    print resp_node.getAttribute('errdesc')
    
#    codes = []
#    codes.append("1-1_01,02,03,04,05,06|07:1:1:1")
##    codes.append("1-4_01,02,03,04,05,06|10:1:1:1")
#    
#    lottery_sd(codes)
    
    
    